package com.example.servlet.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-01 11:43
 **/
public class ServletDemo3 extends HttpServlet {
    private ServletConfig config;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("init3");
        this.config = servletConfig;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("demo3");
        System.out.println("config: " + config);
        System.out.println("getServletContext: " + config.getServletContext());

        if (config != null) {

            Enumeration<String> initParameterNames = config.getInitParameterNames();
            System.out.println(initParameterNames);
            System.out.println("getServletName: " + config.getServletName());
            System.out.println("getInitParameter: " + config.getInitParameter("encoding"));
            while (initParameterNames.hasMoreElements()) {
                String name = initParameterNames.nextElement();
                String value = config.getInitParameter(name);
                System.out.println("name: " + name + " ,value: " + value);
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    public ServletConfig getServletConfig() {
        return super.getServletConfig();
    }

    @Override
    public String getServletInfo() {
        return super.getServletInfo();
    }
}
